void tukey(double *signal, int n, double r)
{
    std::vector<double> window(n);
    std::vector<double> t(n);
    double step = 1.0 / (n - 1);  // 步长计算修正
    for (int i = 0; i < n; i++)   // 循环条件修正
    {
        t[i] = i * step;
    }
    double per = r / 2.0;
    int tl = static_cast<int>(std::floor(per * (n - 1)) + 1);  // tl计算修正
    int th = n - tl + 1;
    for (int i = 0; i < tl; i++)
    {
        window[i] = 0.5 * (1 + cos(M_PI / per * (t[i] - per)));
        signal[i] *= window[i];
    }
    for (int i = tl; i < th; i++)  // th修正
    {
        window[i] = 1;
        signal[i] *= window[i];
    }
    for (int i = th; i < n; i++)  // 循环条件修正
    {
        window[i] = 0.5 * (1 + cos(M_PI / per * (t[i] - 1 + per)));
        signal[i] *= window[i];
    }
}